package com.example.mobile2021606185zhn0406;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    private TextView tvMainTitle;
    private RadioGroup radGupCarType;
    private RadioButton radbtnMainSaloon;
    private RadioButton radbtnMainMVP;
    private RadioButton radbtnMainSUV;
    private RadioGroup radGupMainLine;
    private RadioButton radbtnMainLine1;
    private RadioButton radbtnMainLine2;
    private RadioButton radbtnMainLine3;
    private RadioButton radbtnMainLine4;
    private Button btnMainCreate;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        radGupCarType.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                RadioButton radioButton = findViewById(checkedId);
                Log.i("RadioButton",radioButton.getText().toString());
                Toast.makeText(getApplicationContext(),"你选了" +radioButton.getText(),Toast.LENGTH_LONG).show();
            }

        });
        radGupMainLine.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int i) {
                RadioButton radioButton = findViewById(i);
                Log.i("RadioButton", radioButton.getText().toString());
                Toast.makeText(getApplicationContext(),"你选了" +radioButton.getText(),Toast.LENGTH_LONG).show();
            }
        });
            btnMainCreate.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    String msg = "";
                    int carId =radGupCarType.getCheckedRadioButtonId();
                    if (carId != -1){
                        msg = ((RadioButton)findViewById(carId)).getText().toString();
                    }else{
                        msg = "未选车型";
                    }
                    int lineId = radGupMainLine.getCheckedRadioButtonId();
                    if (lineId != -1){
                        msg += "," + ((RadioButton)findViewById(lineId)).getText().toString();
                    }else{
                        msg += "未选生产线";
                    }
                    Log.i("点击按钮", msg);
                    Toast.makeText(getApplicationContext(),msg,Toast.LENGTH_LONG).show();
                }
            });
    }

    private void initView() {
        tvMainTitle = (TextView) findViewById(R.id.tv_main_title);
        radGupCarType = (RadioGroup) findViewById(R.id.radGup_car_type);
        radbtnMainSaloon = (RadioButton) findViewById(R.id.radbtn_main_saloon);
        radbtnMainMVP = (RadioButton) findViewById(R.id.radbtn_main_MVP);
        radbtnMainSUV = (RadioButton) findViewById(R.id.radbtn_main_SUV);
        radGupMainLine = (RadioGroup) findViewById(R.id.radGup_main_line);
        radbtnMainLine1 = (RadioButton) findViewById(R.id.radbtn_main_line1);
        radbtnMainLine2 = (RadioButton) findViewById(R.id.radbtn_main_line2);
        radbtnMainLine3 = (RadioButton) findViewById(R.id.radbtn_main_line3);
        radbtnMainLine4 = (RadioButton) findViewById(R.id.radbtn_main_line4);
        btnMainCreate = (Button) findViewById(R.id.btn_main_create);
    }
}